//
//  LLCalendarCell.swift
//  LiLi
//
//  Created by liuzhu on 2019/1/14.
//  Copyright © 2019 liuzhu. All rights reserved.
//

import UIKit

class LLCalendarCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    public var day:LLDay?{
        didSet{
            let dayArr = day?.dateStr?.split(separator: "-")
            let dayStr = "\(dayArr?.last ?? "0")"
            let dayArrChinese = day?.chineseDateStr?.split(separator: "-")
            let dayChineseStr = "\(dayArrChinese?.last ?? "0")"
            pointView.isHidden = true
            
            //先判断内容
            if (day?.dayStatus == DayStatusEnum.DAYSTATUS_NODATE) {
                dayLabel.text = ""
                chineseDayLabel.text = ""
            }else{
                dayLabel.text = dayStr
                chineseDayLabel.text = dayChineseStr
            }
            
            //判断字体颜色和背景颜色
            if (day?.dayStatus == DayStatusEnum.DAYSTATUS_NODATE) {
                self.cellBackView.backgroundColor = LLConst.noneGray()
            } else if(day?.dayStatus == DayStatusEnum.DAYSTATUS_CURRENT){
                self.cellBackView.backgroundColor = UIColor.red
                dayLabel.textColor = UIColor.white
                chineseDayLabel.textColor = UIColor.white
            }else if(day?.dayStatus == DayStatusEnum.DAYSTATUS_NOACTION){
                self.cellBackView.backgroundColor = LLConst.backgroundGray()
                dayLabel.textColor = UIColor.darkGray
                chineseDayLabel.textColor = UIColor.darkGray
            }else if(day?.dayStatus == DayStatusEnum.DAYSTATUS_ACTION_SUB){
                self.cellBackView.backgroundColor = LLConst.backgroundGray()
                dayLabel.textColor = UIColor.darkGray
                chineseDayLabel.textColor = UIColor.darkGray
            }else{
                self.cellBackView.backgroundColor = LLConst.actionBlue()
                dayLabel.textColor = UIColor.white
                chineseDayLabel.textColor = UIColor.white
            }
            //判断pointView
            if day?.dayStatus == DayStatusEnum.DAYSTATUS_ACTION_MAIN_SUB || day?.dayStatus == DayStatusEnum.DAYSTATUS_ACTION_SUB {
                pointView.isHidden = false
            }else{
                pointView.isHidden = true
            }
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        contentView.addSubview(cellBackView)
        cellBackView.addSubview(dayLabel)
        cellBackView.addSubview(chineseDayLabel)
        contentView.addSubview(pointView)
        cellBackView.layer.cornerRadius = (self.bounds.size.width-10)/2
        cellBackView.layer.masksToBounds = true
    }
    
    //MARK:- 懒加载
    private lazy var cellBackView:UIView = {
        let ve = UIView.init(frame: CGRect.init(x: 10, y: 0, width: self.bounds.size.width-10, height: self.bounds.size.height-10))
        ve.backgroundColor = LLConst.backgroundGray()
        return ve
    }()
    
    private lazy var dayLabel:UILabel = {
        let la = UILabel.init(frame: CGRect(x: 0, y: 5, width: self.bounds.size.width-10, height: (self.bounds.size.height-20)/2))
        la.textAlignment = NSTextAlignment.center
        la.font = UIFont.systemFont(ofSize: 12)
        return la
    }()
    
    private lazy var chineseDayLabel:UILabel = {
        let la = UILabel.init(frame: CGRect(x: 0, y: dayLabel.frame.origin.y + dayLabel.bounds.size.height, width: self.bounds.size.width-10, height: (self.bounds.size.height-20)/2))
        la.textAlignment = NSTextAlignment.center
        la.font = UIFont.systemFont(ofSize: 10)
        return la
    }()
    
    private lazy var pointView:UIView = {
        let ve = UIView.init(frame: CGRect(x:cellBackView.bounds.size.width/2 + 9, y:cellBackView.bounds.size.height + 4, width: 3, height: 3))
        ve.backgroundColor = UIColor.lightGray
        ve.layer.cornerRadius = 1
        ve.layer.masksToBounds = true
        return ve
    }()
}
